package com.ruoyi.project.travel.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.travel.domain.Appointment;
import com.ruoyi.project.travel.service.IAppointmentService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 预约 Controller
 *
 * @author HYD
 * @date 2020-06-14
 */
@RestController
@RequestMapping("/travel/appointment" )
public class AppointmentController extends BaseController {
    @Autowired
    private IAppointmentService appointmentService;

    /**
     * 查询预约 列表
     */
    @PreAuthorize("@ss.hasPermi('travel:appointment:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(Appointment appointment) {
        startPage();
        QueryWrapper<Appointment> queryWrapper = new QueryWrapper<Appointment>();
        List<Appointment> list = appointmentService.list(queryWrapper);
        return getDataTable(list);
    }

    /**
     * 导出预约 列表
     */
    @PreAuthorize("@ss.hasPermi('travel:appointment:export')" )
    @Log(title = "预约 " , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(Appointment appointment) {
        QueryWrapper<Appointment> queryWrapper = new QueryWrapper<Appointment>(appointment);
        List<Appointment> list = appointmentService.list(queryWrapper);
        ExcelUtil<Appointment> util = new ExcelUtil<Appointment>(Appointment. class);
        return util.exportExcel(list, "appointment" );
    }

    /**
     * 获取预约 详细信息
     */
    @PreAuthorize("@ss.hasPermi('travel:appointment:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(appointmentService.getById(id));
    }

    /**
     * 新增预约 
     */
    @PreAuthorize("@ss.hasPermi('travel:appointment:add')" )
    @Log(title = "预约 " , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Appointment appointment) {
        return toAjax(appointmentService.save(appointment) ? 1 : 0);
    }

    /**
     * 修改预约 
     */
    @PreAuthorize("@ss.hasPermi('travel:appointment:edit')" )
    @Log(title = "预约 " , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Appointment appointment) {
        return toAjax(appointmentService.updateById(appointment) ? 1 : 0);
    }

    /**
     * 删除预约 
     */
    @PreAuthorize("@ss.hasPermi('travel:appointment:remove')" )
    @Log(title = "预约 " , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(appointmentService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
